* Enables content to be moderated by the community.
*/
/**
* Implementation of hook_help().
*/
function queue_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Allows content to be moderated by the community.');
case 'admin/settings/queue':
return t("<p>The queue provides a way for your users to vote on submitted content. This is called <strong>moderation</strong>. Users can moderate a post up (give it a point), or down (subtract a point). The settings below give you control over how many points are required for the status of a post to be automatically changed. See individual items for details.</p>");
$output .= form_select(t('Post threshold'), 'queue_threshold_post', variable_get('queue_threshold_post', 4), $post_and_expire, t('When a post gets this number of moderation points, it is <strong>promoted to the front page</strong> automatically.'));
$output .= form_select(t('Dump threshold'), 'queue_threshold_dump', variable_get('queue_threshold_dump', -2), $dump, t('When a post drops below this number of points, its status is changed to <strong>unpublished</strong>.'));
$output .= form_select(t('Expiration threshold'), 'queue_threshold_expire', variable_get('queue_threshold_expire', 8), $post_and_expire, t('When a post gets this number of points, its status is changed to <strong>unpublished</strong>.'));
$output .= form_item(t('Show comments'), form_checkbox(t('Enabled'), 'queue_show_comments', 1, variable_get('queue_show_comments', 1)), t('Tick the box to show comments below the moderation form.'));
$sql = 'SELECT n.nid, n.title, n.type, u.name, u.uid, SUM(IF(q.uid = %d, 1, 0)) AS voted, SUM(q.vote) AS score FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {queue} q ON n.nid = q.nid WHERE n.moderate = 1 GROUP BY n.nid, n.title, n.type, u.name, u.uid, q.uid, q.vote';
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql('SELECT COUNT(n.nid) FROM {node} n INNER JOIN {queue} q ON n.nid = q.nid WHERE n.moderate = 1');
if ($user->uid != $node->uid && !isset($node->voters[$user->uid])) {
if ($op == t('Vote') && $votes[$edit['vote']]) {
// If it is a valid vote, record it.
queue_vote($node, $edit['vote']);
$output = t('Your vote has been recorded.');
}
else {
// Display some explanation or voting guidelines:
$output .= '<p>'. t('When new content is submitted, it goes into the submission queue. Registered users with the appropriate permission can access this queue and vote whether they think the content should be approved or not. When enough people vote to approve the content, it is displayed on the front page. On the other hand, if enough people vote to drop it, the content will disappear.') .'</p>';
$block['content'] = $output ? $output : t('This node has not yet been moderated.');
}
}
}
return $block;
}
}
/**
* Implementation of hook_nodeapi().
*/
function queue_nodeapi(&$node, $op) {
switch ($op) {
case 'load':
$result = db_query("SELECT uid, vote FROM {queue} WHERE nid = %d", $node->nid);
$node->voters = array();
$node->score = 0;
while ($voter = db_fetch_object($result)) {
$node->voters[$voter->uid] = $voter->vote;
$node->score += $voter->vote;
}
break;
case 'validate':
if ($node->nid && $node->moderate) {
// Reset votes when node is updated:
$node->score = 0;
$node->voters = array();
$node->votes = 0;
}
break;
case 'insert':
if ($node->moderate) {
db_query("INSERT INTO {queue} (nid, uid) VALUES (%d, %d)", $node->nid, $node->uid);
}
case 'update':
if ($node->moderate && user_access('access submission queue')) {
drupal_set_message(t('The post is queued for approval. You can check the votes in the <a href="%queue">submission queue</a>.', array('%queue' => url('queue'))));
}
else if ($node->moderate) {
drupal_set_message(t('The post is queued for approval. The editors will decide whether it should be published.'));